<!--  -->
<template>
  <div class="app-container">
    <el-form :inline="true" size="small">
      <el-form-item label="手机号">
        <el-input
          v-model="mId"
          placeholder="请输入手机号"
          size="small"
        ></el-input>
      </el-form-item>
      <el-form-item label="用户昵称">
        <el-input
          v-model="mName"
          placeholder="请输入用户昵称"
          size="small"
        ></el-input>
      </el-form-item>

      <el-button icon="el-icon-search" type="primary" size="small" @click
        >搜索</el-button
      >
      <el-button icon="el-icon-refresh" size="small" @click>重置</el-button>
      <el-button icon="el-icon-edit" type="warning" size="small" @click="add"
        >新增</el-button
      >
      <el-button icon="el-icon-delete" type="danger" size="small" @click
        >删除</el-button
      >

      <el-button
        class="ref-btn"
        icon="el-icon-refresh"
        circle
        @click
      ></el-button>
    </el-form>
    <el-table :data="tableData" border stripe>
      <template v-for="(i, index) in columns">
        <el-table-column
          v-if="index == 5"
          :key="i.id"
          :label="i.label"
          align="center"
          :width="i.width"
        >
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.isUsed"
              :active-value="1"
              :inactive-value="2"
              @change=""
            >
            </el-switch>
          </template>
        </el-table-column>

        <el-table-column
          v-else
          :prop="i.data"
          :key="i.id"
          :label="i.label"
          align="center"
          :width="i.width"
        />
      </template>
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button
            type="text"
            icon="el-icon-zoom-in"
            @click="detail(scope.$index)"
            >查看</el-button
          >
          <el-button type="text" icon="el-icon-edit" @click="edit(scope.row)"
            >编辑</el-button
          >
          <el-button
            type="text"
            icon="el-icon-delete"
            style="color: #f56c6c; marginright: 10px"
            @click="del(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="page">
      <el-pagination
        @size-change="sizeChange"
        @current-change="currentChange"
        :current-page.sync="page"
        :page-sizes="[20, 40, 80, 100]"
        :page-size="limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      ></el-pagination>
    </div>

    <!-- 对话框 -->
    <el-dialog
      :title="dialogTitle"
      :visible.sync="showDialog"
      width="40%"
      @close="showDialog = false"
    >
      <el-form
        v-model="form"
        ref="form"
        :rules="rules"
        label-width="120px"
        :inline="false"
        size="normal"
      >
        <el-form-item label="模板编号" prop="id">
          <el-input
            v-model="form.id"
            placeholder="请填写模板编号"
            style="width: 220px"
          />
        </el-form-item>
        <el-form-item label="模板名称" prop="name">
          <el-input
            v-model="form.name"
            placeholder="请填写模板名称"
            style="width: 220px"
          />
        </el-form-item>
        <el-form-item label="自动发送" prop="autoSend">
          <el-switch
            v-model="form.autoSend"
            :active-value="1"
            :inactive-value="2"
            @change=""
          />
        </el-form-item>
        <el-form-item label="模板内容" prop="content">
          <el-input
            v-model="form.content"
            type="textarea"
            placeholder="请填写可预约数量"
            style="width: 420px"
          />
        </el-form-item>
        <el-form-item label="附带优惠券" prop="content">
          <el-button
            type="text"
            style="text-decoration: underline"
            @click="showTicket = true"
            >添加</el-button
          >
          <el-button
            type="text"
            style="text-decoration: underline; color: #ff6666"
            @click=""
            >删除</el-button
          >
        </el-form-item>
      </el-form>
      <el-dialog
        title="选择优惠券"
        :visible.sync="showTicket"
        width="30%"
        append-to-body
      >
        <el-select
          v-model="ticket"
          placeholder="请选择优惠券"
          multiple
          clearable
          filterable
          @change=""
        >
          <el-option label="优惠券1" value="1" />
          <el-option label="优惠券2" value="2" />
          <el-option label="优惠券3" value="3" />
        </el-select>

        <span slot="footer">
          <el-button type="primary" @click="">确定</el-button>
          <el-button @click="showTicket = false">取消</el-button>
        </span>
      </el-dialog>

      <span slot="footer">
        <el-button @click="showDialog = false">取消</el-button>
        <el-button type="primary" @click>确定</el-button>
      </span>
    </el-dialog>

    <!-- 发送用户列表 -->
    <el-dialog
      title="查看"
      :visible.sync="showDetail"
      width="40%"
      @close="showDetail = false"
    >
      <div class="detBox">
        <div class="baseDetail">
          <div class="detTitle">基本信息</div>
          <div class="detListBox">
            <div class="detList">
              <div class="delLab">用户头像</div>
              <div class="delVal">{{tableData[i].avatar}}</div>
            </div>
             <div class="detList">
              <div class="delLab">用户昵称</div>
              <div class="delVal">{{tableData[i].userName}}</div>
            </div>
             <div class="detList">
              <div class="delLab">手机号</div>
              <div class="delVal">{{tableData[i].phone}}</div>
            </div>
             <div class="detList">
              <div class="delLab">生日</div>
              <div class="delVal">{{tableData[i].birthDay}}</div>
            </div>

             <div class="detList">
              <div class="delLab">性别</div>
              <div class="delVal">{{tableData[i].sex}}</div>
            </div>
             <div class="detList">
              <div class="delLab">收入</div>
              <div class="delVal">{{tableData[i].income}}</div>
            </div>
             <div class="detList">
              <div class="delLab">地区</div>
              <div class="delVal">{{tableData[i].area}}</div>
            </div>
             <div class="detList">
              <div class="delLab">职业</div>
              <div class="delVal">{{tableData[i].profession}}</div>
            </div>

          </div>
        </div>
        <el-divider direction="horizontal"></el-divider>
         <div class="baseDetail">
          <div class="detTitle">其他信息</div>
          <div class="detListBox">
            <div class="detList">
              <div class="delLab">下单数量</div>
              <div class="delVal">{{tableData[i].count}}</div>
            </div>
             <div class="detList">
              <div class="delLab">检测次数</div>
              <div class="delVal">{{tableData[i].test}}</div>
            </div>
             <div class="detList">
              <div class="delLab">下单总额</div>
              <div class="delVal">{{tableData[i].total}}</div>
            </div>
             <div class="detList">
              <div class="delLab">社群群主</div>
              <div class="delVal">{{tableData[i].admin}}</div>
            </div>
          </div>
          
        </div>
      </div>
      <span slot="footer">
        <el-button type="primary" @click="">确定</el-button>
        <el-button @click="showDetail = false">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "slider",
  data() {
    return {
      mId: "",
      mName: "",
      keyword: "",
      page: 1,
      limit: 10,
      total: 10,
      i:0,//详情索引值

      dialogTitle: "创建",
      form: {},
      showDialog: false,
      showDetail: false,
      showTicket: false,
      ticket: [],
      sendUser: [],
      tableData: [
        {
          id: "001",
          phone: "13311223344",
          birthDay: "2000-02-21",
          userName: "用户名",
          avatar: "消息模板1",
          sex: "女",
          income: "10K-15K",
          profession: "职业名称",
          area: "北京市昌平区",
          count: "123",
          total: "444",
          test: "12",
          admin: "无",
          isUsed: 1,
        },
        {
          id: "002",
          phone: "13344221133",
          birthDay: "1991-02-21",
          userName: "用户名2",
          avatar: "消息模板3",
          sex: "男",
          income: "20K-35K",
          profession: "职业名称2",
          area: "北京市海淀区",
          count: "1233",
          total: "4434",
          test: "122",
          admin: "无2",
          isUsed: 1,
        },
        {
          id: "003",
          phone: "13311223344",
          birthDay: "1998-02-21",
          userName: "用户名3",
          avatar: "消息模板1",
          sex: "女",
          income: "10K-12K",
          profession: "职业名称",
          area: "北京市丰台区",
          count: "400",
          total: "1233",
          test: "69",
          admin: "管理员",
          isUsed: 2,
        },
      ],
      rules: {
        id: [{ required: true }],
        name: [{ required: true }],
        autoSend: [{ required: true }],
        // content: [{ required: true }]
      },

      columns: [
        { key: 0, label: `手机号`, data: "phone", visible: true, width: "180" },
        { key: 1, label: `用户昵称`, data: "userName", visible: true },
        { key: 2, label: `头像`, data: "avatar", width: "120" },
        { key: 3, label: `性别`, data: "sex", visible: true },
        { key: 3, label: `地区`, data: "area", visible: true },
        { key: 3, label: `是否启用`, data: "isUsed", visible: true },
      ],
      artQuery: {
        id: "1",
      },
    };
  },
  created() {},
  methods: {
    add() {
      this.showDialog = true;
    },
    detail(i) {
      this.i=i;
      this.showDetail = true;
    },
    edit(i) {
      this.showDialog = true;
    },
    del(i, d) {
      this.$confirm('确认删除所选数据？', "确认删除", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.tableData.splice(i, 1);
        })
        .catch(() => {});
    },
    send() {
      this.showUser = true;
    },
    sizeChange() {},
    beforeCoverUpload() {},
    currentChange() {},
  },
};
</script>
<style scoped>
.slideImg {
  width: 140px;
}
.baseDetail{
  width: 100%;
}
.detTitle{
  font-weight: bold;
  margin-left: 20px;
  margin-bottom: 10px;
  margin-top: -15px;
}
.detListBox{
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}
.detList{
  width: 50%;
  min-width: 200px;
  margin: 10px 0;
  /* border: 1px solid #000; */
  display: flex;
}
.delLab{
  width: 35%;
  margin-right: 20px;
  text-align: right;
}
</style>
